﻿using STMS.BLL;
using STMS.STMSapp.FModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace STMS.STMSapp.store
{
    public partial class FrmStoreInfo : Form
    {
      
        private FInfoData fInfoData = new FInfoData();
        private StoreBLL storeBLL = new StoreBLL();
        public FrmStoreInfo(FInfoData fInfoData)
        {
            
            InitializeComponent();
            this.Tag = fInfoData;
            InitFromStoreInfo();

        }
        public  void InitFromStoreInfo()
        {
            fInfoData = this.Tag as FInfoData; 
            if( fInfoData != null )
            {
                switch(fInfoData.ActType)
                {
                    // 新增页面
                    case 1:
                        groupBox1.Text = "新增仓库";
                        this.Text = "新增仓库";
                        break;
                    // 修改仓库信息页面
                    case 2:
                        groupBox1.Text = "修改仓库";
                        this.Text = "修改仓库";
                        break;

                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            string storeName = tbStoreName.Text;
            string storeNo = tbStoreNo.Text;
            string storeRemark = tbStoreMark.Text;
            if (string.IsNullOrEmpty(storeName))
            {
                MessageBox.Show("仓库名称不能为空!");
                tbStoreName.Focus();
                return;
            }
            else
            {
                storeBLL.AddStore(storeName, Int32.Parse(storeNo), storeRemark);
                this.Hide();
            }


        }

        private void tbStoreNo_KeyPress(object sender, KeyPressEventArgs e)
        {
            //如果输入的不是退格和数字，则屏蔽输入
            if (!(e.KeyChar == 8 || (e.KeyChar >= 48 && e.KeyChar <= 57)))
            {
                e.Handled = true;
            }
        }

        public event Action ReLoadStoreList; // 刷新仓库列表数据

    }
}
